﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Arizu.Repository;
using System.Web.SessionState;
using System.Data;
using System.Text;

namespace AiRiZu.User
{
    public class UserMessage : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            AirizuMessage aMessage = AirizuMessage.CreateInstance();

            if (context.Session["logId"] == null)
            {
                return;
            }

            DataTable dt = aMessage.GetUnreadMesage(int.Parse(context.Session["logId"].ToString()));
            StringBuilder sBuilder = new StringBuilder();

            aMessage.GetUnreadMesage(int.Parse(context.Session["logId"].ToString()));

            if (dt.Rows.Count > 0)
            {
                sBuilder.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> <thead>");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    sBuilder.Append(" <tr>");
                    sBuilder.Append("<th width=\"100\">").Append(dt.Rows[i]["Message"].ToString()).Append("</th>");
                    sBuilder.Append(" </tr>");
                }
                sBuilder.Append("</thead> <tbody> </tbody> </table>");
                
            }

            context.Response.ContentType = "text/plain";
            context.Response.Write(sBuilder.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
